(function(){

    refreshErTbale();

    var currentData;
    $(document).on('click','button',function(e){
        e.stopPropagation();
        if ($(this).attr('id') == 'btn-undo'){
            commandManager.undo();
        }else if ($(this).attr('id') == 'btn-redo'){
            commandManager.redo();
        }else if ($(this).attr('id') == 'btn-print'){
            paper.print();
        }else if ($(this).attr('id') == 'btn-clear'){
            graph.clear();
        }else if ($(this).attr('id') == 'btn-svg'){
            paper.openAsSVG();
        }else if ($(this).attr('id') == 'btn-png'){
            paper.openAsPNG();
        }else if ($(this).attr('id') == 'btn-svg'){
            paper.openAsSVG();
        }else if ($(this).attr('id') == 'btn-search'){

            /*if(currentData == undefined){
                layer.open({
                    title: '提示',
                    content: '还没有加载对象',
                    shade: 0
                });
            }else {
                layer.open({
                    type:2,
                    content:['/assets/custom/draw/searchTable2.html'],
                    title:'搜索类型',
                    area:['600px','450px']
                })
            }*/
                console.log(JSON.stringify(graph.toJSON()));
        }else if ($(this).attr('id') == 'btn-refresh'){
            refreshErTbale();
        }else if ($(this).attr('id') == 'btn-save'){
            e.stopPropagation();
            var json = graph.toJSON();
            console.log(json);
            var dataObjectsPosition = new Array();
            $.each(json.cells, function (i, v) {
                if (v.type == 'link') {
                    return;
                }
                var json_position =
                    {
                        "modelId": $("base").attr("modelId"),
                        "objectId": v.id,
                        "positionX": v.position.x,
                        "positionY": v.position.y,
                        "positionWidth": v.size.width,
                        "positionHeight": v.size.height
                    };
                dataObjectsPosition.push(json_position)
            });

            $.ajax({
                url: '/rest/dataModel/savePosition',
                type: 'POST',
                dataType: 'json',
                data: {"posList": JSON.stringify(dataObjectsPosition)},
                success: function (data) {
                    console.log('成功');
                    layer.open({
                        title: '提示'
                        , content: '保存成功',
                        shade: 0
                    });
                },
                error: function (data) {
                    layer.open({
                        title: '提示'
                        , content: '保存失败',
                        shade: 0
                    });
                    console.log('网络异常')
                }
            })
        }else if ($(this).attr('id') == 'btn-layout'){
            $.ajax({
                url : requestUrl+'/rest/webpage/render/fullPosition',
                type: 'POST',
                dataType: 'JSON',
                data : {"dsId":dsId,"modelId":modelId, "rawType":rawType},
                success: function (data) {
                    $.each(data.object.dataObjects,function(i,v){
                        var cell = graph.getCell(v.objectId);

                        cell.position(v.positionVo.positionX,v.positionVo.positionY)  //移动元素的位置
                    })

                },
                error : function(data){
                    console.log(data)
                }
            })
        }
    })

    function len(s) {
        var l = 0;
        var a = s.split("");
        for (var i=0;i<a.length;i++) {
            if (a[i].charCodeAt(0)<299) {
                l++;
            } else {
                l+=2;
            }
        }
        return l;
    }

    function refreshErTbale(){

    }

})();








